<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>

    <style type="text/css">
        a:link, a:visited {
            text-decoration: none; /*超链接无下划线*/
        }

        a:hover {
            text-decoration: none; /*鼠标放上去有下划线*/
        }
    </style>

    <style type="text/css">
        body {
            font-size: 15pt
        }

        td {
            font-size: 15pt
        }

        tr {
            font-size: 15pt
        }
    </style>

    <style type=text/css>
        body {
            background-image: url(back_fore.jpg);
            background-repeat: no-repeat;
            background-position: center top;
        }
    </style>

    <script type="text/javascript">
        function show_div1() {
            var obj_div = document.getElementById("starlist1");
            obj_div.style.display = (obj_div.style.display == 'none') ? 'block'
                : 'none';
        }

        function hide_div1() {
            var obj_div = document.getElementById("starlist1");
            obj_div.style.display = (obj_div.style.display == 'none') ? 'block'
                : 'none';
        }

        function show_div2() {
            var obj_div = document.getElementById("starlist2");
            obj_div.style.display = (obj_div.style.display == 'none') ? 'block'
                : 'none';
        }

        function hide_div2() {
            var obj_div = document.getElementById("starlist2");
            obj_div.style.display = (obj_div.style.display == 'none') ? 'block'
                : 'none';
        }

        function show_div3() {
            var obj_div = document.getElementById("starlist3");
            obj_div.style.display = (obj_div.style.display == 'none') ? 'block'
                : 'none';
        }

        function hide_div3() {
            var obj_div = document.getElementById("starlist3");
            obj_div.style.display = (obj_div.style.display == 'none') ? 'block'
                : 'none';
        }

        function show_div4() {
            var obj_div = document.getElementById("starlist4");
            obj_div.style.display = (obj_div.style.display == 'none') ? 'block'
                : 'none';
        }

        function hide_div4() {
            var obj_div = document.getElementById("starlist4");
            obj_div.style.display = (obj_div.style.display == 'none') ? 'block'
                : 'none';
        }

        function show_div5() {
            var obj_div = document.getElementById("starlist5");
            obj_div.style.display = (obj_div.style.display == 'none') ? 'block'
                : 'none';
        }

        function hide_div5() {
            var obj_div = document.getElementById("starlist5");
            obj_div.style.display = (obj_div.style.display == 'none') ? 'block'
                : 'none';
        }
    </script>

    <title>基于范例推理的台风相似性预测</title>
</head>
<body>
<?php
/**
 * 对台风进行基于案例推理的路径预测
 * 通过GET方式得到台风的编号和预测起始点
 *
 * @author 周利发    zhoulifa@126.com
 */
error_reporting(~E_NOTICE);

// ------判断是否有GET------
$num_typhoon = isset ($_GET ["num"]) ? $_GET ["num"] : 20130029;
$begin_point = isset ($_GET ["beg"]) ? $_GET ["beg"] : 13;

// ------基本设定------
$baseurl = "show.php";

$config = parse_ini_file("config/db_config.ini");
$server = $config["server"];
$username = $config["username"];
$password = $config["password"];
$database = $config["database"];

// ------函数定义------
/**
 *
 * @name angle_typhoon
 *       计算两个地理位置的连线与地球纬线两条直线之间的夹角
 * @param double $lat_f1
 *            第一个地点的经度
 * @param double $long_f1
 *            第一个地点的纬度
 * @param double $lat_f2
 *            第二个地点的经度
 * @param double $long_f2
 *            第二个地点的纬度
 * @return number 返回夹角的角度值
 */
function angle_typhoon($lat_f1, $long_f1, $lat_f2, $long_f2)
{ // f2->f1
    if ($lat_f1 < $lat_f2)
        $long_c = ( float )(6371.004 * cos($lat_f1 * pi() * 2 / 360) * 2 * pi());
    else
        $long_c = ( float )(6371.004 * cos($lat_f2 * pi() * 2 / 360) * 2 * pi());

    // ------经度距------
    $x = $long_c * ($long_f1 - $long_f2) / 360;
    // ------纬度距------
    $y = 6371.004 * 2 * pi() * ($lat_f1 - $lat_f2) / 360;
    // echo $x . "####" . $y . '<br>';
    if ($x == 0) {
        $angle = 90;
    } else {
        $angle = atan(abs($y / $x)) * 180 / pi();
    }
    if ($x > 0 && $y < 0) {
        $angle = 360 - $angle;
    } else if ($x <= 0 && $y < 0) {
        $angle = 180 + $angle;
    } else if ($x < 0 && $y >= 0) {
        $angle = 180 - $angle;
    }
    return $angle;
}

$query = "select * from typhoon_total where num = " . $num_typhoon;
$conn = mysqli_connect($server, $username, $password, $database);
$result = mysqli_query($conn, $query);

// ------输出表的字段------
// $num_result=mysql_fetch_row($result);
// for($i=0;$i<mysql_num_fields($result);$i++)
// {
// echo mysql_field_name($result, $i).' ';
// }

// ------判断是否数据库是否有数据返回------
if (mysqli_fetch_row($result) == 0) {
    echo '<br />no total date<br />';
    exit ();
}
mysqli_data_seek($result, 0);
while ($num_result = mysqli_fetch_row($result)) {
    // ------输出表的记录------
    // for($i = 0; $i < mysql_num_fields ( $result ); $i ++) {
    // echo $num_result [$i] . ' ';
    // }
    // echo '<br>';
    $num_typhoon = $num_result [0];
    // $flat_typhoon=$num_result[1];
    $name_typhoon = $num_result [2];
    $time_typhoon = $num_result [3];
    $count_typhoon = $num_result [4];
    // $level_typhoon=$num_result[5];
}

// ------存储待预测台风记录点数据的变量定义------
$time_forecast = array();
$hour_forecast = array();
$level_forecast = array();
$lat_forecast = array();
$long_forecast = array();
$pres_forecast = array();
$wnd_forecast = array();
$flat_forecast = array();
$no_forecast = array();
$speed_forecast = array();

// ------从数据库获取待预测台风记录点数据------
$query = "select * from typhoon_detail where num = " . $num_typhoon;
$result = mysqli_query($conn, $query);

// ------判断是否数据库是否有数据返回------
if (mysqli_fetch_row($result) == 0) {
    echo '<br />no detail date<br />';
    exit ();
}
mysqli_data_seek($result, 0);
while ($num_result = mysqli_fetch_row($result)) {
    // ------输出表的记录------
    // for($i = 0; $i < mysql_num_fields ( $result ); $i ++) {
    // echo $num_result [$i] . ' ';
    // }
//    if ($num_result [9] <= $begin_point) {
    $num_forecast [$num_result [9] - 1] = $num_result [0];
    // echo $num_forecast . ' ';
    $time_forecast [$num_result [9] - 1] = $num_result [1];
    // echo $time_forecast [$num_result [9] - $begin_point + 1] . ' ';
    $hour_forecast [$num_result [9] - 1] = $num_result [2];
    // echo $hour_forecast [$num_result [9] - $begin_point + 1] . ' ';
    $level_forecast [$num_result [9] - 1] = $num_result [3];
    // echo $level_forecast . ' ';
    $lat_forecast [$num_result [9] - 1] = $num_result [4];
    // echo $lat_forecast [$num_result [9] - $begin_point + 1] . ' ';
    $long_forecast [$num_result [9] - 1] = $num_result [5];
    // echo $long_forecast [$num_result [9] - $begin_point + 1] . ' ';
    $pres_forecast [$num_result [9] - 1] = $num_result [6];
    // echo $pres_forecast . ' ';
    $wnd_forecast [$num_result [9] - 1] = $num_result [7];
    // echo $wnd_forecast . ' ';
    $flat_forecast [$num_result [9] - 1] = $num_result [8];
    // echo $flat_forecast . ' ';
    $no_forecast [$num_result [9] - 1] = $num_result [9];
    // echo $no_forecast [$num_result [9] - $begin_point + 1] . ' ';
    $speed_forecast [$num_result [9] - 1] = $num_result [10];
    // echo $speed_forecast [$num_result [9] - $begin_point + 1] . ' ';
//    }
}

// -----－删除typhoon_forecast数据库表中已有的待预测数据------
$query_delete = "delete from typhoon_forecast where num = " . $num_typhoon;
$result_delete = mysqli_query($conn, $query_delete);

// ------判断来源------
$pre = isset ($_GET ["pre"]) ? $_GET ["pre"] : 0;
if (strcmp($pre, "list") == 0) {
    $temp_point = $count_typhoon;
} else {
    $temp_point = $begin_point;
}
// ------待预测点存入typhoon_forecast数据库------
for ($i = 0; $i < $temp_point; $i++) {
    // ------构成插入SQL语句------
    $query_insert = "INSERT INTO typhoon_forecast ";
    $query_insert = $query_insert . "(`num`, `date`, `hour`, `level`, `lat`, `long`, `pres`, `wnd`, `flat`, `no`, `speed_last`) ";
    $query_insert = $query_insert . "VALUES ('";
    $query_insert = $query_insert . $num_forecast [$i] . "', '";
    $query_insert = $query_insert . $time_forecast [$i] . "', '";
    $query_insert = $query_insert . $hour_forecast [$i] . "', '";
    $query_insert = $query_insert . $level_forecast [$i] . "', '";
    $query_insert = $query_insert . $lat_forecast [$i] . "', '";
    $query_insert = $query_insert . $long_forecast [$i] . "', '";
    $query_insert = $query_insert . $pres_forecast [$i] . "', '";
    $query_insert = $query_insert . $wnd_forecast [$i] . "', '";
    $query_insert = $query_insert . $flat_forecast [$i] . "', '";
    $query_insert = $query_insert . $no_forecast [$i] . "', '";
    $query_insert = $query_insert . $speed_forecast [$i] . "');";
    // echo $query;
    $result_insert = mysqli_query($conn, $query_insert);
}

// ------输出预测台风的经纬度------
// echo $lat_forecast [$begin_point-2] . ' ' . $long_forecast [$begin_point-2] . ' ' . $lat_forecast [$begin_point-1] . ' ' . $long_forecast [$begin_point-1] . '<br>';
// ------待预测台风的移向------
$angle_forecast = angle_typhoon($lat_forecast [$begin_point - 1], $long_forecast [$begin_point - 1], $lat_forecast [$begin_point - 2], $long_forecast [$begin_point - 2]);
// echo $angle_forecast . '<br>';

// ------每个月份的天数------
$Month = array(
    31,
    28,
    31,
    30,
    31,
    30,
    31,
    31,
    30,
    31,
    30,
    31
);

// ------预测台风判据标准------
$threshold_season = 15;
$threshold_geography = 220.505;
$threshold_direction = 22.5;
$threshold_speedratio = 0.5;

// ------待预测台风发生的时间(年月日)------
$year_forecast = ( int )substr($time_forecast [$begin_point - 1], 0, 4);
$month_forecast = ( int )substr($time_forecast [$begin_point - 1], 5, 2);
$day_forecast = ( int )substr($time_forecast [$begin_point - 1], 8, 2);
// echo '<br>' . $year_forecast . ' ' . $month_forecast . ' ' . $day_forecast . '<br>';

// ------判断当年是否是闰年------
if (($year_forecast % 4 == 0 && $year_forecast % 100 != 0) || $year_forecast % 400 == 0)
    $Month [1]++;
// echo $Month[1];

$flat = true;
// ------利用循环控制相似台风的个数------
while (true) {

    // ------存储为已判定为相似台风变量的定义------
    $num_typhoon_similary = array(); // 存储相似台风编号
    $name_typhoon_similary = array(); // 存储相似台风英文名称
    $time_typhoon_similary = array(); // 存储相似台风发生时间
    $lat_typhoon_similary = array();
    $long_typhoon_similary = array();
    $point_typhoon_similary = array(); // 存储相似台风记录点数
    $value_similary = array(); // 存储相似台风相似度
    $count_typhoon_similary = 0; // 存储相似台风数目

    // echo '<br>***********************************************************<br>';
    // ------求得季节相似的下限------
    if ($day_forecast - $threshold_season <= 0) {
        $month_fl = ($month_forecast + 10) % 12 + 1;
        $day_fl = $day_forecast - $threshold_season + $Month [($month_forecast + 10) % 12];
    } else {
        $month_fl = $month_forecast;
        $day_fl = $day_forecast - $threshold_season;
    }
    // ------求得季 节相似的上限------
    if ($day_forecast + $threshold_season > $Month [$month_forecast - 1]) {
        $month_up = $month_forecast % 12 + 1;
        $day_up = $day_forecast + $threshold_season - $Month [$month_forecast - 1];
    } else {
        $month_up = $month_forecast;
        $day_up = $day_forecast + $threshold_season;
    }
    // echo $month_fl . ' ' . $day_fl . ' ' . $month_up . ' ' . $day_up;

    // ------将季节相似上下限转化为字符型------
    if ($month_fl > 9) {
        $date_fl = ( string )($month_fl);
    } else {
        $date_fl = '0' . ( string )($month_fl);
    }
    if ($month_up > 9) {
        $date_up = ( string )($month_up);
    } else {
        $date_up = '0' . ( string )($month_up);
    }
    if ($day_fl > 9) {
        $date_fl = $date_fl . ( string )($day_fl);
    } else {
        $date_fl = $date_fl . '0' . ( string )($day_fl);
    }
    if ($day_up > 9) {
        $date_up = $date_up . ( string )($day_up);
    } else {
        $date_up = $date_up . '0' . ( string )($day_up);
    }
    // echo $date_fl . ' ' . $date_up;

    // ------构成SQL语句，筛选符合季节相似的台风 ------
    if ($date_fl <= $date_up) {
        $query = "SELECT * FROM typhoon_total where substring(date, 5, 4) between ";
        $query = $query . $date_fl . " and ";
        $query = $query . $date_up . " and flat = 0;";
    } else {
        $query = "SELECT * FROM typhoon_total where substring(date, 5, 4) between ";
        $query = $query . $date_fl . " and 1231";
        $query = $query . " or substring(date, 5, 4) between 0101 and ";
        $query = $query . $date_up . " and flat=0;";
    }
    // echo $query;
    $result = mysqli_query($conn, $query);

    // ------判断是否数据库是否有数据返回------
    if (mysqli_fetch_row($result) == 0) {
        echo '<br />数据库找不到数据！' . $query . '<br />';
        exit ();
    }
    mysqli_data_seek($result, 0);
    while ($num_result = mysqli_fetch_row($result)) {
        // ------输出表的记录------
        // for($i = 0; $i < mysql_num_fields ( $result ); $i ++) {
        // echo $num_result [$i] . ' ';
        // }
        // echo '<br>';
        $flat = false;
        $num_similary = $num_result [0];
        // $flat_similary=$num_result[1];
        $name_similary = $num_result [2];
        $time_similary = $num_result [3];
        $count_similary = $num_result [4];
        // $level_similary=$num_result[5];

        // ------存储相似台风的记录点的变量定义------
        // $time_similary = array ();
        $year_similary = array();
        $month_similary = array();
        $day_similary = array();
        $hour_similary = array();
        $lat_similary = array();
        $long_similary = array();
        $no_similary = array();
        $speed_similary = array();

        // ------构成SQL语句，筛选相似台风的记录点------
        $query = "SELECT * FROM typhoon_detail where num = " . $num_similary . " and flat = 0;";
        $result_similary = mysqli_query($conn, $query);

        // ------判断是否数据库是否有数据返回------
        if (mysqli_fetch_row($result_similary) == 0) {
            echo '<br />数据库找不到数据！' . $query . '<br />';
            exit ();
        }
        mysqli_data_seek($result_similary, 0);
        while ($num_rt = mysqli_fetch_row($result_similary)) {
            // ------输出表的记录------
            // for($i = 0; $i < mysql_num_fields ( $result_similary ); $i ++) {
            // echo $num_rt [$i] . ' ';
            // }
            // echo '<br>';

            // ------存储相似台风记录点------
            // $time_similary [$num_rt [9] - 1] = $num_rt [1];
            $year_similary [$num_rt [9] - 1] = ( int )substr($num_rt [1], 0, 4);
            $month_similary [$num_rt [9] - 1] = ( int )substr($num_rt [1], 5, 2);
            $day_similary [$num_rt [9] - 1] = ( int )substr($num_rt [1], 8, 2);
            $hour_similary [$num_rt [9] - 1] = $num_rt [2];
            $lat_similary [$num_rt [9] - 1] = $num_rt [4];
            $long_similary [$num_rt [9] - 1] = $num_rt [5];
            $no_similary [$num_rt [9] - 1] = $num_rt [9];
            $speed_similary [$num_rt [9] - 1] = $num_rt [10];
        }

        // ------地理相似计算------
        for ($i = 1; $i < $count_similary; $i++) {
            if ($lat_similary [$i] < $lat_forecast [$begin_point - 1])
                $long_c = 6371.004 * cos($lat_similary [$i] * pi() * 2 / 360) * 2 * pi();
            else
                $long_c = 6371.004 * cos($lat_forecast [$begin_point - 1] * pi() * 2 / 360) * 2 * pi();
            $x_2 = pow($long_c * abs($long_similary [$i] - $long_forecast [$begin_point - 1]) / 360, 2);
            $y_2 = pow(6371.004 * 2 * pi() * abs($lat_similary [$i] - $lat_forecast [$begin_point - 1]) / 360, 2);
            // ------两个记录点之间的距离------
            $dis = sqrt($x_2 + $y_2);
            // echo $long_c . ' ' . $x_2 . ' ' . $y_2 . ' ' . $dis . '<br>';

            if ($dis < $threshold_geography) {

                // ------移向相似计算------
                $angle_similary = angle_typhoon($lat_similary [$i], $long_similary [$i], $lat_similary [$i - 1], $long_similary [$i - 1]);
                if (abs($angle_similary - $angle_forecast) < $threshold_direction) {
                    // echo $angle_similary . '***' . $i . ':' . $angle_forecast;

                    // ------移速相似计算------
                    if (abs($speed_forecast [$begin_point - 1] - $speed_similary [$i]) < ($threshold_direction * $speed_forecast [$begin_point - 1])) {
                        // echo '<br>speed:' . $speed_forecast [$begin_point-1] . ' ' . $speed_similary [$i];
                        // ------保存相似台风------
                        $num_typhoon_similary [$count_typhoon_similary] = $num_similary;
                        $name_typhoon_similary [$count_typhoon_similary] = $name_similary;
                        $time_typhoon_similary [$count_typhoon_similary] = $time_similary;
                        $lat_typhoon_similary [$count_typhoon_similary] = $lat_similary [$i + 2];
                        $long_typhoon_similary [$count_typhoon_similary] = $long_similary [$i + 2];
                        $point_typhoon_similary [$count_typhoon_similary] = $i + 1 + 1;
                        $value_similary [$count_typhoon_similary] = 1 - pow($dis / $threshold_geography, 2);
                        $count_typhoon_similary++;

                        // ------输出符合要求的相似台风------
                        // echo '<br>' . $num_typhoon_similary [$count_typhoon_similary - 1];
                        // echo ' ' . $point_typhoon_similary [$count_typhoon_similary - 1];
                        // echo ' ' . $value_similary [$count_typhoon_similary - 1] . '<br>';
                    } // ---移速相似判据
                } // ---移向相似判据
            } // ---地理相似判据
        } // ---对历史台风中的每个记录点进行遍历
        // if ($count_typhoon_similary >= 10)
        // break;
    } // ---符合季节相似的台风的遍历

    if ($flat) {
        break;
    }

    // ------当相似台风的数目超过十个时，则缩小判据准标------
    /*
     * if ($count_typhoon_similary > 10) {
     * // echo "相似台风数目过多，重新确立判据范围";
     * // $threshold_season = ( int ) ($threshold_season * 2.0 / 3);
     * $threshold_geography *= 0.9;
     * $threshold_direction *= 0.9;
     * if ($threshold_speedratio == 0) {
     * echo '<br />error<br />';
     * exit ();
     * }
     * $threshold_speedratio -= 0.1;
     * // ------当相似台风的数目少于四个时，则放宽判据准标------
     * } else if ($count_typhoon_similary < 4) {
     * // echo "相似台风数目过少，放宽判据范围";
     * // $threshold_season = ( int ) ($threshold_season * 4.0 / 3);
     * $threshold_geography *= 1.1;
     * $threshold_direction *= 1.1;
     * if ($threshold_direction >= 270) {
     * echo '<br />error<br />';
     * exit ();
     * }
     * $threshold_speedratio += 0.1;
     * // ------当相似台风的数目适当时------
     * } else {
     */

    // ------相似度排序------
    for ($i = 0; $i < $count_typhoon_similary; $i++) {
        for ($j = $i + 1; $j < $count_typhoon_similary; $j++) {
            if ($value_similary [$i] < $value_similary [$j]) {
                $temp = $value_similary [$i];
                $value_similary [$i] = $value_similary [$j];
                $value_similary [$j] = $temp;

                $temp = $num_typhoon_similary [$i];
                $num_typhoon_similary [$i] = $num_typhoon_similary [$j];
                $num_typhoon_similary [$j] = $temp;

                $temp = $point_typhoon_similary [$i];
                $point_typhoon_similary [$i] = $point_typhoon_similary [$j];
                $point_typhoon_similary [$j] = $temp;

                $temp = $lat_typhoon_similary [$i];
                $lat_typhoon_similary [$i] = $lat_typhoon_similary [$j];
                $lat_typhoon_similary [$j] = $temp;

                $temp = $long_typhoon_similary [$i];
                $long_typhoon_similary [$i] = $long_typhoon_similary [$j];
                $long_typhoon_similary [$j] = $temp;

                $temp = $name_typhoon_similary [$i];
                $name_typhoon_similary [$i] = $name_typhoon_similary [$j];
                $name_typhoon_similary [$j] = $temp;

                $temp = $time_typhoon_similary [$i];
                $time_typhoon_similary [$i] = $time_typhoon_similary [$j];
                $time_typhoon_similary [$j] = $temp;
            }
        }
    }
    $flat_similary = array();
    for ($i = 0; $i < $count_typhoon_similary; $i++) {
        if ($num_typhoon_similary[$i] == $num_typhoon) {
            $flat_similary[$i] = 0;
            continue;
        }
        for ($j = 0; $j < $i; $j++) {
            if ($num_typhoon_similary[$i] == $num_typhoon_similary[$j]) {
                break;
            }
        }
        if ($j != $i) {
            $flat_similary[$i] = 0;
            continue;
        }
        $flat_similary[$i] = 1;
    }

    // ------输出所有的相似台风，并找到相似度最大的相似台风------
    $max_similary = 0;
    for ($i = 0; $i < $count_typhoon_similary; $i++) {
        if ($num_typhoon_similary [$i] != $num_typhoon) {
            $max_similary = $i;
            break;
        }
    }
    $number_typhoon = 0;
    echo '<table background="back_fore_table.png" border="1" cellspacing="0px" cellpadding="2px" align="center">';
    echo '<tr><td align="center">';
    echo '★★★★★★★★★★★★★★★</th></tr>';
    echo '<tr><td align="center">与' . $num_typhoon . '相似的气旋分别为</td></tr>';
    for ($i = 0; $i < $count_typhoon_similary; $i++) {
        if ($flat_similary[$i]) {
            echo '<tr><td background="back_table.png" align="center">';
            echo '<a href="javascript:show_div' . ($number_typhoon + 1) . '()"><font color="red">&nbsp;&nbsp;&nbsp;>>';
            echo $num_typhoon_similary [$i] . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></a>';
            echo '<div id="starlist' . ($number_typhoon + 1) . '" style="display: none" align="left">';
            echo '<p><font size="4pt">&nbsp;&nbsp;&nbsp;&nbsp;英文名：' . $name_typhoon_similary [$i] . '</font><br />';
            echo '<font size="4pt">&nbsp;&nbsp;&nbsp;&nbsp;发生时：' . substr($time_typhoon_similary [$i], 0, 4);
            echo '年' . substr($time_typhoon_similary [$i], 4, 2);
            echo '月' . substr($time_typhoon_similary [$i], 6, 2);
            echo '日</font><br />';
            echo '<font size="4pt">&nbsp;&nbsp;&nbsp;&nbsp;相似度：';
            printf("%.3f", $value_similary [$i]);
            echo '</font><br /><font size="4pt">&nbsp;&nbsp;&nbsp;&nbsp;相似点：第' . $point_typhoon_similary [$i] . '个</font><br />';
            echo '<font size="4pt">&nbsp;&nbsp;&nbsp;&nbsp;预测点：' . $lat_typhoon_similary [$i] . '°N,';
            echo $long_typhoon_similary [$i] . '°E<p>';

            // -----－删除typhoon_forecast数据库表中已有的相似台风数据------
            $query_delete = "delete from typhoon_forecast where num = " . $num_typhoon_similary[$i];
            $result_delete = mysqli_query($conn, $query_delete);

            // ------将从高到低对应相似度的相似台风的记录点输出------
            $query = "SELECT * FROM typhoon_detail where num = " . $num_typhoon_similary [$i] . " and flat = 0;";
            $result = mysqli_query($conn, $query);

            // ------判断是否数据库是否有数据返回------
            if (mysqli_fetch_row($result) == 0) {
                echo '<tr><td align="center">无法搜索到相似台风</td></tr>';
                echo '<tr><td>★★★★★★★★★★★★★★★</td></tr>';
                exit ();
            }

            // ------存入相似台风与预测台风的连接点------
            $query_insert = "INSERT INTO app_bjxytyphoon.typhoon_forecast ";
            $query_insert = $query_insert . "(`num`, `date`, `hour`, `level`, `lat`, `long`, `pres`, `wnd`, `flat`, `No`, `speed_last`) ";
            $query_insert = $query_insert . "VALUES ('";
            $query_insert = $query_insert . $num_typhoon_similary[$i] . "', '";
            $query_insert = $query_insert . $time_forecast[$begin_point - 1] . "', '";
            $query_insert = $query_insert . $hour_forecast[$begin_point - 1] . "', '";
            $query_insert = $query_insert . $level_forecast[$begin_point - 1] . "', '";
            $query_insert = $query_insert . $lat_forecast[$begin_point - 1] . "', '";
            $query_insert = $query_insert . $long_forecast[$begin_point - 1] . "', '";
            $query_insert = $query_insert . $pres_forecast[$begin_point - 1] . "', '";
            $query_insert = $query_insert . $wnd_forecast[$begin_point - 1] . "', '";
            $query_insert = $query_insert . $flat_forecast[$begin_point - 1] . "', '";
            $query_insert = $query_insert . "1', '";
            $query_insert = $query_insert . $speed_forecast[$begin_point - 1] . "');";
            // echo $query;
            $result_insert = mysqli_query($conn, $query_insert);

            mysqli_data_seek($result, 0);
            while ($num_result = mysqli_fetch_row($result)) {
                // ------判断当前记录点是否为最大相似度台风的预测点------
                if ($num_result [9] >= $point_typhoon_similary [$i] || $num_result [9] >= ($point_typhoon_similary [$i] + 1)) {
                    // ------输出表的记录------
                    // for($i = 0; $i < mysql_num_fields ( $result ); $i ++) {
                    // echo $num_result [$i] . ' ';
                    // }
                    // echo '<br>';
                    $iii = $num_result [9] - $point_typhoon_similary [$i] + 1;
                    if ($iii > 4) {
                        break;
                    }
                    $date_insert = $time_forecast [$begin_point - 1];
                    $hour_insert = ( int )$hour_forecast [$begin_point - 1] + 6 * $iii;
                    // ------当时间超过24小时，为日期加一天------
                    if ($hour_insert >= 24) {
                        $hour_insert -= 24;
                        $day_insert = ( int )substr($date_insert, 8, 2);
                        $day_insert++;
                        // ------将日期转化为字符型------
                        if ($day_insert >= 10)
                            $day_insert = ( string )$day_insert;
                        else
                            $day_insert = '0' . (( string )$day_insert);
                        $date_insert = substr($date_insert, 0, 8) . $day_insert;
                    }

                    // ------将小时转化为字符型------
                    if ($hour_insert == 0) {
                        $hour_insert = "00";
                    } elseif ($hour_insert == 6) {
                        $hour_insert = "06";
                    } else {
                        $hour_insert = ( string )$hour_insert;
                    }
                    // ------将预测结果存入typhoon_forecast数据库表中------
                    // ------构成插入SQL语句------
                    $query_insert = "INSERT INTO app_bjxytyphoon.typhoon_forecast ";
                    $query_insert = $query_insert . "(`num`, `date`, `hour`, `level`, `lat`, `long`, `pres`, `wnd`, `flat`, `No`, `speed_last`) ";
                    $query_insert = $query_insert . "VALUES ('";
                    $query_insert = $query_insert . $num_typhoon_similary[$i] . "', '";
                    $query_insert = $query_insert . $num_result [1] . "', '";
                    $query_insert = $query_insert . $num_result [2] . "', '";
                    $query_insert = $query_insert . "*" . "', '";
                    $query_insert = $query_insert . $num_result [4] . "', '";
                    $query_insert = $query_insert . $num_result [5] . "', '";
                    $query_insert = $query_insert . $num_result [6] . "', '";
                    $query_insert = $query_insert . $num_result [7] . "', '";
                    $query_insert = $query_insert . $num_result [8] . "', '";
                    $query_insert = $query_insert . ($iii + 1) . "', '";
                    $query_insert = $query_insert . $num_result [10] . "');";
                    // echo $query;
                    $result_insert = mysqli_query($conn, $query_insert);
                } // ---查找相似度最大的台风的预测点
            } // ---相似度最大的台风预测点的输出

            if ($iii != 5) {
                $iii++;
            }

            // ------表单------
            echo '<form action="' . $baseurl . '" method="get">';
            echo '<input type="hidden" name="num" value="' . $num_typhoon_similary[$i] . ';' . $num_typhoon . '"/>';
            echo '<input type="hidden" name="table" value="typhoon_forecast"/>';
            echo '<input type="hidden" name="count" value="' . $iii . ';' . $temp_point . '"/>';//($no_insert)
            echo '<table border="0" cellspacing="0px" cellpadding="0px" align="center"><tr><td align="center">>>是否在地图上展示预测结果? <p><input type="image" src="yes.png"/>';
            echo '</td></tr></table></form></div>';
            echo '</td></tr>';
            $number_typhoon++;
        }
        if ($number_typhoon > 4) {
            break;
        }
    }

    echo '<tr><td>★★★★★★★★★★★★★★★</td></tr>';
    echo '</table>';
    break;
}
?>
</body>
</html>